import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;




public class Test {


    public static void main1(String[] args) {
        Double x = 1.2;
        double l = 1.2;
        float f2 = Double.valueOf(x/l).floatValue();
        int a = 10;

        System.out.println(f2);
    }

    /**
     * 截断句子
     * @param s
     * @param k
     * @return
     */
    //https://leetcode.cn/problems/truncate-sentence/
    public String truncateSentence(String s, int k) {
        if(k == 0) {
            return s;
        }
        int i = 0;//记录空格次数
        int j = 0;//遍历字符串
        while(i < k) {
            if(j >= s.length()) {
                return s;
            }
            char ch = s.charAt(j);
            if(ch == ' ') {
                i++;
                j++;
            }else {
                j++;
            }
        }
        return s.substring(0,j-1);

    }

    /**
     * 原地删除重复元素
     * @param nums
     * @return
     */
    //https://leetcode.cn/problems/remove-duplicates-from-sorted-array/
    public int removeDuplicates(int[] nums) {
        int[] flag = new int[201];
        int k = nums.length;//记录数组长度
        for (int i = nums.length-1; i >=0; i--) {
            int tmp = flag[nums[i]+100];
            if(tmp >=1) {
                for (int j = i; j < k-1; j++) {
                    nums[j] = nums[j+1];
                }
                k--;
            }else {
                flag[nums[i]+100]++;
            }
        }
        return k;
    }
    public int removeDuplicates2(int[] nums) {
        if(nums == null || nums.length == 0) {
            return 0;
        }

        int i = 0;
        int j = 1;
        while(j < nums.length) {
            if(nums[i] == nums[j]) {
                j++;
            }else {
                i++;
                nums[i] = nums[j];
            }
        }
        return i+1;

    }


}
